function [ f, g ] = bgfsBoost( X, row, col, val, m, n, lambda, grad )

U = X(1:m, :);
V = X(m + 1:end, :);

assert(n == size(V, 1));

res = partXY(U', V', row, col, length(row));
res = res' - val;

% function value
f = (1/2)*sum(res.^2) + (lambda/2)*sum(X(:).^2);

% gradient
if nargout > 1
    grad = setSval(grad, res, length(res));

    g = zeros(size(X));

    g(1:m, :) = grad*V + lambda*U;
    g(m + 1:end, :) = grad'*U + lambda*V;
end

end

